<?php

abstract class BasePresenter extends NPresenter
{
	public $oldLayoutMode = FALSE;
	public $user;
	/** @persistent */
	public $noJs;


	/** @persistent */
	public $selectFirst;

	protected $hodnoty = null;

	protected function startup() {
        
		
		$this->user = $this->getUser();
		$presenter = explode(':',$this->name);
		
		if($presenter[0] == 'Admin'){
			if (!$this->user->isLoggedIn()) {
				
				if ($this->user->getLogoutReason() === NUser::INACTIVITY) {
					$this->flashMessage('Z důvodu neaktivity jste byl/a odhlášen/a.');
				}
				
				if(isset($presenter[1]) && $presenter[1] != 'Login'){
					
					$backlink = $this->getApplication()->storeRequest();
					$this->redirect(':Login:', array('backlink' => $backlink));
				}
			}else{
				
				$this->template->logged = $this->user->getIdentity()->data['email'];
				$this->template->role = $this->user->getIdentity()->data['role'];
			}
		}
		
	
		parent::startup();
		
		NFormContainer::extensionMethod('NFormContainer::addDependentSelectBox','DependentSelectBox::formAddDependentSelectBox');
		NFormContainer::extensionMethod("addJsonDependentSelectBox", "DependentSelectBox\JsonDependentSelectBox::formAddJsonDependentSelectBox");
		NFormContainer::extensionMethod('addDatePicker', function (NFormContainer $container, $name, $label = NULL) {
			return $container[$name] = new DatePicker($label);
		});
		DependentSelectBox::$disableChilds = $this->selectFirst === null;
	}

	protected function beforeRender(){
		$souteze = new SoutezModel();
		$this->template->ligy = $souteze->findAll()->fetchAll();
		
		
	}

}
